package com.example.leetdemo.finash;

public class Solution2043 {

    public static void main(String[] args) {

    }


    class Bank {
        long[] balance;

        public Bank(long[] balance) {
            this.balance = balance;
        }

        public boolean transfer(int account1, int account2, long money) {
            if (!checkIsExists(account1) || !checkIsExists(account2)) {
                return false;
            }
            if (balance[account1 - 1] < money) {
                return false;
            } else {
                balance[account1 - 1] -= money;
                balance[account2 - 1] += money;
                return true;
            }
        }

        public boolean deposit(int account, long money) {
            if (!checkIsExists(account)) {
                return false;
            }
            balance[account - 1] += money;
            return true;
        }

        public boolean withdraw(int account, long money) {
            if (!checkIsExists(account)) {
                return false;
            }
            if (balance[account - 1] < money) {
                return false;
            } else {
                balance[account - 1] -= money;
                return true;
            }
        }

        private boolean checkIsExists(Integer account) {
            if (balance.length < account - 1) {
                return false;
            }
            if (account < 0) {
                return false;
            }
            return true;
        }
    }
}
